package com.nifostasky.comic.business.controller;

import com.nifostasky.comic.common.utils.StringLocalUtil;
import com.nifostasky.comic.entitys.CoHistoryRecord;
import com.nifostasky.comic.entitys.CoOtherPicture;
import com.nifostasky.comic.entitys.CoSpiderInfo;
import com.nifostasky.comic.service.CoCollectInfoService;
import com.nifostasky.comic.service.CoHistoryRecordService;
import com.nifostasky.comic.service.CoOtherPictureService;
import com.nifostasky.comic.service.CoSpiderInfoService;
import com.nifostasky.comic.vos.CoSpiderDetailedInfoVO;
import com.nifostasky.comic.vos.JsonResult;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 各种操作
 */
@RestController
@RequestMapping("/operationController")
@Api(tags = "用户操作")
@Slf4j
@ApiSort(9999)
@AllArgsConstructor
public class UserOperationController {
    private CoCollectInfoService coCollectInfoService;
    private CoSpiderInfoService coSpiderInfoService;
    private CoHistoryRecordService coHistoryRecordService;
    private CoOtherPictureService coOtherPictureService;
    /**
     * 收藏漫画
     */
    @ApiOperation("收藏漫画")
    @PostMapping("/saveCollectComic")
    @ApiOperationSupport(order = 1)
    public JsonResult saveCollectComic(@RequestBody CoSpiderDetailedInfoVO info){
        return new JsonResult(coCollectInfoService.saveCollectComic(info));
    }

    /**
     * 取消收藏漫画
     */
    @ApiOperation("取消收藏漫画")
    @GetMapping("/cancelCollectComic")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "收藏漫画id,多个id时,号隔开", dataType = "String", required = true),
    })
    @ApiOperationSupport(order = 2)
    public JsonResult cancelCollectComic(String ids){
        List<Long> longs = StringLocalUtil.changeLongList(ids);
        return new JsonResult(coCollectInfoService.cancelCollectComic(longs));
    }


    /**
     * 增加python文件
     */
    @ApiOperation("增加python文件")
    @PostMapping("/addCoSpiderInfo")
    @ApiOperationSupport(order = 3)
    public JsonResult addCoSpiderInfo(@RequestBody CoSpiderInfo info){
        return new JsonResult(coSpiderInfoService.addCoSpiderInfo(info));
    }

    /**
     * 删除python文件
     */
    @ApiOperation("删除python文件")
    @GetMapping("/deleteCoSpiderInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "python文件id,多个id时,号隔开", dataType = "String", required = true),
    })
    @ApiOperationSupport(order = 4)
    public JsonResult deleteCoSpiderInfo(String ids){
        List<Long> longs = StringLocalUtil.changeLongList(ids);
        return new JsonResult(coSpiderInfoService.deleteCoSpiderInfo(longs));
    }

    /**
     * 增加历史记录
     */
    @ApiOperation("增加历史记录")
    @PostMapping("/saveHistoryRecord")
    @ApiOperationSupport(order = 5)
    public JsonResult saveHistoryRecord(@RequestBody CoHistoryRecord history){
        return new JsonResult(coHistoryRecordService.saveHistoryRecord(history));
    }

    /**
     * 新增修改轮播图
     */
    @ApiOperation("新增修改轮播图")
    @PostMapping("/addAndEditRotationPicture")
    @ApiOperationSupport(order = 6)
    public JsonResult addAndEditRotationPicture(@RequestBody CoOtherPicture pictureInfo){
        return new JsonResult(coOtherPictureService.addAndEditRotationPicture(pictureInfo));
    }

    /**
     * 新增修改本站推荐漫画
     */
    @ApiOperation("新增修改本站推荐漫画")
    @PostMapping("/addAndEditCollectComic")
    @ApiOperationSupport(order = 7)
    public JsonResult addAndEditCollectComic(@RequestBody CoOtherPicture pictureInfo){
        return new JsonResult(coOtherPictureService.addAndEditCollectComic(pictureInfo));
    }
}
